/**
 * 主机编辑
 */
define(['module/component/views/FormView',
        'module/hostapp/action/HostAppAction',
        'module/hostapp/tools/tools',
        "text!module/hostapp/templates/AppEdit.html"],
	   function(FormView, hostAppAction, Tools, HostEditHtml){
		  return ngc.View.extend({
			  events: {
				'click #btnSubmit' : 'btnSubmitClick',
				'click #btnCancel' : 'btnCancelClick',
		      },
		      _appform: function(){
			      return this.getView("#form_content");
			  },
			  btnSubmitClick: function(){
				  if(!this._appform().valid()){
					  ngc.info("必填信息不完整！");
					  return;
				  }
				  //获取当前表单数据
			      var appData = this._appform().getValues();
			      if(this.options.type == "edit"){
			    	  appData.id = this.options.rowData.id;
			      }
			      var sendData = {
			    		  type : this.options.type,
			    		  appData : appData
			      }
			      hostAppAction.editApp(sendData, function(data){
			    	  if(data.status == "SUCCESS"){
			    		  if(this.options.type == "edit"){
			    			  ngc.info("主机信息操作成功");
			    		  }else{
			    			  ngc.info("主机信息操作成功");
			    		  }
			    		  this.btnCancelClick();
			    	  }
			      }.bind(this));
			  },
			  btnCancelClick:function(){
				  this.trigger("editView", {});
			      this.popup.close();
			  },
			  render:function(){
				  this.$el.append(ngc.compile(HostEditHtml));
				  this.initWidget();
				  this._initAppForm();
			  },
			  _initAppForm: function(){
				  var _that = this;
				  var config_elements = 
					  [{
							id: 'province',
							label: '省份',
							type : 'select',
							editable:true,
							enumCode : "province",
							required:true,
							rule : "描述:required",
						}, {
							id: 'unitUsage',
							label: '运营商',
							type : 'select',
							enumCode : "unitUsage",
							required:true,
							rule : "描述:required",
						}, {
							id: 'product',
							label: '所属产品',
							type : 'select',
							enumCode : "product",
							required:true,
							rule : "描述:required",
						}, {
							id: 'localhost',
							label: '位置',
							type : 'select',
							enumCode : "localhost",
							required:true,
							rule : "描述:required",
						}, {
							id: 'projectType',
							label: '项目类型',
							type : 'select',
							enumCode : "projectType",
							required:true,
							rule : "描述:required",
						}, {
							id: 'environmentType',
							label: '环境类型',
							type : 'select',
							enumCode : "environmentType",
							required:true,
							rule : "描述:required",
						}, {
							id : 'projectName',
							type : 'text',
							label : '项目名称',
							required:true,
							rule : "描述:required",
						}, {
							id : 'ip',
							type : 'text',
							label : 'ip'
						}, {
							id : 'url',
							type : 'text',
							label : '应用URL'
						}, {
							id : 'appAccount',
							type : 'text',
							label : '应用登录用户名'
						}, {
							id : 'appPassword',
							type : 'text',
							label : '应用登录密码'
						}, {
							id : 'tel',
							type : 'text',
							label : '电话'
//						}, {
//							id : 'purpose',
//							type : 'text',
//							label : '用途'
						}, {
							id : 'responsibility',
							type : 'text',
							label : '项目负责人'
//						}, {
//							id : 'submitDate',
//							type : 'date',
//							label : '确定时间',
//							format: 'yyyy-mm-dd'
						}, {
							id : 'sqlMsg',
							type : 'text',
							label : '数据库信息'
						}, {
							id : 'deployPath',
							type : 'text',
							label : '部署路径'
						}, {
							id : 'logPath',
							type : 'text',
							label : '日志路径'
						}, {
							id : 'middleware',
							type : 'text',
							label : '中间件'
						}, {
							id : 'notes',
							type : 'text',
							label : '备注'
						}];
				  	this.setView("#form_content", new FormView({
			    		config : {
							elements : config_elements,
							column: 2
						}
			    	}));
			    	this.getView("#form_content").on("viewRenderAfter", function() {
			    		if(_that.options.type == "edit"){
			    			this.setValues(_that.options.rowData);
			    			this.initValue("submitDate", {value: _that.options.rowData.submitDate});
			    		}
			    		if(_that.options.type == "show"){
			    			this.setValues(_that.options.rowData);
			    			_that.$("#btnSubmit").hide();
			    			this.initValue("submitDate", {value: _that.options.rowData.submitDate});
			    		}
			    		
					});
			  },
			  _initHostForm: function(){
				  var _that = this;
				  var config_elements = 
					  [{
							id: 'hostId',
							label: '主机',
							type : 'select',
							enumCode : "cloud_host",
						}, {
							id : 'port',
							type : 'text',
							label : '端口'
						}, {
							id : 'deployPath',
							type : 'text',
							label : '部署路径'
						}, {
							id : 'logPath',
							type : 'text',
							label : '日志路径'
						}, {
							id : 'notes',
							type : 'text',
							label : '备注'
						}];
				  	this.setView("#form_host_content", new FormView({
			    		config : {
							elements : config_elements,
							column: 2
						}
			    	}));
			    	this.getView("#form_host_content").on("viewRenderAfter", function() {
			    		if(_that.options.type == "edit" || _that.options.type == "show"){
			    			this.setValues(_that.options.rowData);
			    			this.initValue("notes", {value: _that.options.rowData.notesr});
			    		}
					});
			  },
			  initWidget:function(){
		    	 this.$("#tabs").tabs({
					canClose:false,
					paging: false,
					autoResizable:true
				 });
			  },
			  afterRender: function(){
			  }
		  });
});